import 'package:auntserver/model/entitys.dart';
import 'package:flutter/cupertino.dart';
import 'package:provider/provider.dart';

class PreciousScreen extends StatefulWidget {
  final String args;

  PreciousScreen(this.args);

  @override
  _PreciousScreenState createState() => _PreciousScreenState();
}

class _PreciousScreenState extends State<PreciousScreen>
    with WidgetsBindingObserver {
  String str;

  @override
  Widget build(BuildContext context) {
    checkIsNull("build");
    return Container(
      child: Center(child: GestureDetector(onTap: () {
        setState(() {
          str = str + "xlb" ;
        });
      }, child: Text(str))),
    );
  }
  void checkIsNull(String tag){
    print(context==null?"$tag----context是空":context.toString()+"IOIOIOIO");
  }

  @override
  void initState() {
    super.initState();
    checkIsNull("initState");
    str = "Precious";
    print("Precious:initState");
    WidgetsBinding.instance.addPostFrameCallback((_) {
      print("Precious:addPostFrameCallback");
    });
    // WidgetsBinding.instance.addPersistentFrameCallback((_) {
    //   print("addPersistentFrameCallback");
    // });
    WidgetsBinding.instance.addObserver(this);
    WidgetsBinding.instance.addTimingsCallback((timings) {
      timings.forEach((element) {
        print("Precious:addTimingsCallback" + element.toString());
      });
    });
  }


  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    print("Precious:didChangeDependencies");
    checkIsNull("didChangeDependencies");

  }

  @override
  void dispose() {
    super.dispose();
    print("Precious:dispose");
    checkIsNull("dispose");
  }

  @override
  void reassemble() {
    super.reassemble();
    print("Precious:reassemble");
    checkIsNull("reassemble");
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    super.didChangeAppLifecycleState(state);
    print("Precious:didChangeAppLifecycleState: $state");
  }

  ///当前系统改变了一些访问性活动的回调
  @override
  void didChangeAccessibilityFeatures() {
    super.didChangeAccessibilityFeatures();
    print("Precious:didChangeAccessibilityFeatures");
  }

  ///低内存回调
  @override
  void didHaveMemoryPressure() {
    super.didHaveMemoryPressure();
    print("Precious:didHaveMemoryPressure");
  }

  ///用户本地设置变化时调用，如系统语言改变
  @override
  void didChangeLocales(List<Locale> locale) {
    super.didChangeLocales(locale);
    print("Precious:didChangeLocales");
  }

  ///应用尺寸改变时回调，例如旋转
  @override
  void didChangeMetrics() {
    super.didChangeMetrics();
    Size size = WidgetsBinding.instance.window.physicalSize;
    print("Precious:didChangeMetrics  ：宽：${size.width} 高：${size.height}");
  }

  /// {@macro on_platform_brightness_change}
  @override
  void didChangePlatformBrightness() {
    super.didChangePlatformBrightness();
    print("Precious:didChangePlatformBrightness");
  }

  ///文字系数变化
  @override
  void didChangeTextScaleFactor() {
    super.didChangeTextScaleFactor();
    print(
        "Precious:didChangeTextScaleFactor:${WidgetsBinding.instance.window.textScaleFactor}");
  }
}
